class Robot {

    enum Direction {
        East,
        South,
        West,
        North
    }

    private int width;
    private int height;
    private int locX;
    private int locY;
    private Direction direction;

    public Robot(int width, int height) {
        this.width = width;
        this.height = height;
        this.locX = 0;
        this.locY = 0;
        this.direction = Direction.East;
    }

    public void step(int num) {
        int totalLength = 4*(width+height);
        num = num % totalLength;


        while (num > 0) {
            int directionMaxStep = getDirectionMaxStep();
            int nextStep = Math.min(num, directionMaxStep);
            stepSameDirection(nextStep);
            num = num - nextStep;


            if (num > 0) {
                changeDirection();
            }
        }
    }

    public int[] getPos() {
        return new int[]{locX, locY};
    }

    public String getDir() {
        return direction.name();
    }

    private void stepSameDirection(int num) {
        switch (direction) {
            case East: {
                locX = locX + num;
                break;
            }
            case West: {
                locX = locX - num;
                break;
            }
            case North: {
                locY = locY + num;
                break;
            }
            case South: {
                locY = locY - num;
                break;
            }
            default: {
                throw new RuntimeException("unknown direction");
            }
        }
    }

    private int getDirectionMaxStep() {
        switch (direction) {
            case East: {
                return width - locX - 1;
            }
            case West: {
                return locX;
            }
            case North: {
                return height - locY - 1;
            }
            case South: {
                return locY;
            }
            default: {
                throw new RuntimeException("unknown direction");
            }
        }
    }

    private void changeDirection() {
        switch (direction) {
            case East: {
                direction = Direction.North;
                return;
            }
            case North: {
                direction = Direction.West;
                return;
            }
            case West: {
                direction = Direction.South;
                return;
            }
            case South: {
                direction = Direction.East;
                return;
            }
            default:
                throw new RuntimeException("unknown direction");
        }
    }

    private boolean isNextStepOutEdge() {
        switch (direction) {
            case East: {
                return locX >= width - 1;
            }
            case West: {
                return locX <= 0;
            }
            case North: {
                return locY >= height - 1;
            }
            case South: {
                return locY <= 0;
            }
            default:
                throw new RuntimeException("unknown direction");
        }
    }
}

/**
 * Your Robot object will be instantiated and called as such:
 * Robot obj = new Robot(width, height);
 * obj.step(num);
 * int[] param_2 = obj.getPos();
 * String param_3 = obj.getDir();
 */